package com.knight.service;

import java.util.List;

import com.knight.model.Menu;

/**
 * 菜单service
 * 
 * @author YQ
 *
 */
public class MenuService {

	private static MenuService instance = new MenuService();

	private MenuService() {
	}

	public static MenuService getInstance() {
		return instance;
	}

	private static final Menu dao = new Menu().dao();

	public List<Menu> findMenuByType(String type, String status) {
		List<Menu> list = dao
				.find("SELECT name,url FROM menu WHERE TYPE=" + type + " AND STATUS=" + status + " ORDER BY sortValue");
		return list;
	}

	public Menu findByPrimaryKey(String id) {
		return dao.findById(id);
	}

	/**
	 * 通过类型和父级Id
	 * 
	 * @param type
	 * @param parentId
	 * @return
	 */
	public List<Menu> findMenuByparentId(String type, String parentId) {
		List<Menu> list = dao
				.find("SELECT * FROM menu WHERE TYPE=" + type + " AND parentId=" + parentId + " ORDER BY sortValue");
		return list;
	}

}
